﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess
{
  public  class SortUrl
    {
      /// <summary>
      /// 生成短链接
      /// </summary>
      /// <param name="longurl"></param>
      /// <returns></returns>
      public static string CreateShortUrl(string longurl)
      {
          string content = string.Empty;
          string url = "http://f-2.cc/home/surl?url=" + System.Web.HttpUtility.UrlEncode(longurl);
          HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
          req.Method = "GET";
          try
          {
              using (WebResponse wr = req.GetResponse())
              {
                  StreamReader weatherStreamReader = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.UTF8);
                  content = weatherStreamReader.ReadToEnd();
              }
          }
          catch (Exception ex)
          {
              return "";
          }
          return content;
      }
    }
}
